package com.situ.dao;

import com.situ.entity.Category;
import com.situ.util.DBUtil;

import java.util.List;

/**
 * @author yangkx
 * @create 2023-09-09-1:12
 */
public class CategoryDao {

    //查询表格数据
    public List<Category> list() {
        String sql = "select * from category";
        return DBUtil.executeDQL(sql, Category.class);
    }

    //发请求去查分类数据
    public List<Category> all() {
        String sql = "select * from category";
        return DBUtil.executeDQL(sql, Category.class);
    }

    //保存
    public void insert(Category c) {
        String sql = "insert into category(name) values(?)";
        DBUtil.executeDML(sql,c.getName());
    }

    //更新
    public void update(Category c) {
        String sql = "update category set name=? where id=?";
        DBUtil.executeDML(sql,c.getName(),c.getId());
    }

    //删除分类数据
    public void delete(Integer id) {
        String sql = "delete from category where id = ?";
        DBUtil.executeDML(sql,id);
    }

    //根据id查分类数据 带到前台
    public List<Category> selectById(Integer id) {
        String sql = "select * from category where id = ?";
        return DBUtil.executeDQL(sql, Category.class,id);
    }


}
